#include "qt_radio_ui.h"
#include "login_ui.h"
#include "room.h"
#include <QtGui>



MainDialog::MainDialog()
{
    int cnt=0;
    createGridGroupBox();
    createMusicGroupBox();
    createIdGroupBox();

    okButton = new QPushButton(tr("OK"));
    cancelButton = new QPushButton(tr("Cancel"));
    okButton->setDefault(true);

    connect(buttons[0], SIGNAL(clicked()), this, SLOT(play()));
    connect(enterButton, SIGNAL(clicked()), this, SLOT(ok()));
    connect(buttons[1], SIGNAL(clicked()), this,SLOT(add()));
    QHBoxLayout *buttonLayout = new QHBoxLayout;
    buttonLayout->addStretch(1);
    buttonLayout->addWidget(okButton);
    buttonLayout->addWidget(cancelButton);
    
    QVBoxLayout *rightLayout =new QVBoxLayout;
    rightLayout->addWidget(musicGroupBox);
    rightLayout->addWidget(idGroupBox);

    QHBoxLayout *groundLayout = new QHBoxLayout;
    groundLayout->addWidget(gridGroupBox);
    

    
   
    
    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addLayout(groundLayout);
    mainLayout->addLayout(rightLayout);


    curdir =new QDir("./musicbox");
    for(cnt = 0; cnt < curdir->entryList().count(); cnt++) {
    if(!(curdir->entryList().at(cnt)=="." | curdir->entryList().at(cnt)==".."))
	musiclistwidget->addItem(curdir->entryList().at(cnt));
    };    


   RoomDialog *roomdia=new RoomDialog(this);
   Dialog *login=new Dialog(roomdia);
   login->show();
 



   setLayout(mainLayout);
    resize(600,400);
    setWindowTitle(tr("Radio Star"));

   

}
void MainDialog::createIdGroupBox(){

    idGroupBox = new QGroupBox(tr("Id"));
    QVBoxLayout *layout =new QVBoxLayout;  
    
    idlistwidget = new QListWidget(this);
   
    layout->addWidget(idlistwidget);
   
    idGroupBox->setLayout(layout);
}

void MainDialog::createMusicGroupBox()
{
    musicGroupBox = new QGroupBox(tr("Music"));
    QVBoxLayout *layout = new QVBoxLayout;
    buttons[1] = new QPushButton(tr("add"));
    buttons[0] = new QPushButton(tr("play"));
    musiclistwidget = new QListWidget(this);
    


    layout->addWidget(musiclistwidget);
    layout->addWidget(buttons[0]);
    layout->addWidget(buttons[1]);

    musicGroupBox->setLayout(layout);
}

void MainDialog::createGridGroupBox()
{
    gridGroupBox = new QGroupBox(tr("chatting"));
    QGridLayout *layout = new QGridLayout;

 
    lineEdits = new QLineEdit;
    layout->addWidget(lineEdits,5,0);
   
   enterButton = new QPushButton(tr("input"));
   layout->addWidget(enterButton,5,1);    
     
    smallEditor = new QTextEdit;
    layout->addWidget(smallEditor,0,0,4,2);
    gridGroupBox->setLayout(layout);
}
void MainDialog::ok(){
smallEditor->append("id : "+lineEdits->text());
lineEdits->clear();
}
void MainDialog::play(){

//fileName = QFileDialog::getOpenFileName(this,tr("Open File"),"","ALL (*.wav)");

//QFile file(fileName);
//if(file.open(QFile::ReadOnly | QFile::Text)){}
}
void MainDialog::add(){


 QFileDialog *fileDIG=new QFileDialog(this);
// fileDIG->setFileMode(QFileDialog::AnyFile);
 QString fileName = QFileDialog::getOpenFileName(this,tr("Open File"),".musicbox","ALL (*.wav)");

}

